package soccerscope.training.conditions;

import soccerscope.model.ClientScene;
import soccerscope.model.PlayMode;
import soccerscope.model.WorldModel;
import soccerscope.model.PlayMode.PLAY_MODE;

public class PlayModeCondition
    extends GameCondition {

  PLAY_MODE[]       playModes  = null;

  private PLAY_MODE fulfilling = null;

  public PlayModeCondition() {

    super();
  }

  public void setPlayModes(PLAY_MODE[] playModes) {

    this.playModes = playModes;
  }

  public PLAY_MODE[] getPlayModes() {

    return this.playModes;
  }

  /**
   * This method overrides the isTrue() method from gamecondition to specifiy
   * the behaviour of the Play_Mode Condition
   */
  @Override
  public boolean isTrue(ClientScene scene) {

    if (this.playModes == null) {
      return false;
    }
    for (PLAY_MODE p : this.playModes) {
      if (p == PlayMode.allPlayModes[scene.pmode.pmode]) {
        this.setFulfillingPMode(p);
        System.out
            .println("" + WorldModel.getSceneSet().lastScene().time + " PlayMode-Condition fulfilled: " + p);
        return true;
      }
    }
    return false;
  }

  public int getFulfillingIndex() {

    return this.fulfilling.ordinal() + 3;
  }

  private void setFulfillingPMode(PLAY_MODE pm) {

    this.fulfilling = pm;
  }

  public int[] getStatIndizes() {

    int s = this.playModes.length;
    int[] indizes = new int[s];
    for (int i = 0; i < s; i++) {
      indizes[i] = this.playModes[i].ordinal() + 3;
    }
    return indizes;
  }
}
